home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18033 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: fiesta.srl.ford.com!usenet
  2. From: jmccall4@sl0270.srl.ford.com (James McCallum)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help! What's wrong with this?
  5. Date: 18 Apr 1996 15:05:11 GMT
  6. Organization: SRL, Ford Motor Company
  7. Distribution: world
  8. Message-ID: <4l5ln7$sr7@fiesta.srl.ford.com>
  9. References: <4l22v3$1beo@useneta1.news.prodigy.com>
  10. Reply-To: jmccall4@sl0270.srl.ford.com
  11. NNTP-Posting-Host: cae002.srl.ford.com
  12.  
  13. In article <4l22v3$1beo@useneta1.news.prodigy.com>, NEKU72A@prodigy.com (Brian Munroe) writes:
  14. >I'm trying to learn C++ and I've run into a strange problem in the 
  15. >following code.
  16. >
  17. [main part deleted]
  18. >
  19. >void get_customer_info(char temp[ADD_LEN], int flag)
  20. >{ int answer;
  21. >  int len;
  22. >  clrscr();
  23. >  switch (flag)
  24. >  { case 0:
  25. >     cout << "Enter the bidder's name in one of the following forms.\n";
  26. >     cout << "  Person: LAST NAME, FIRST NAME\n";
  27. >     cout << "  Business: COMPANY NAME\n\n";
  28. >     break;
  29. >    case 1:
  30. >     cout << "\nEnter first line of address\n";
  31. >     break;
  32. >    case 2:
  33. >     cout << "\nEnter second line of address\n";
  34. >     break;
  35. >    case 3:
  36. >     cout << "\nEnter third line of address\n";
  37. >     break;
  38. >    default:
  39. >     exit(1);
  40. >  }
  41. >  cin >> temp;
  42.    ^^^^^^^^^^^^
  43. this will throw away any leading white space characters, read the first item in the
  44. input list up to the first white space characters, and put that in temp. Any 
  45. remaining items in the list will he left for the next read. If your input is like
  46. Blogs, Joe for the first read, temp will be "Blogs,". The next time you call this
  47. Function, temp will be "Joe" (and not the first line of the address as desired).
  48. Try printing out the string after each function call.
  49. You can get around this by either repeatedly calling cin to get all items in the 
  50. list before returning from the function, or using cin.getline() function to get
  51. everything up to the next \n in the input stream.
  52.  
  53. >  len = strlen(temp);
  54. >  if (len < ADD_LEN)
  55. >   { strncat(temp, "                                        ",ADD_LEN-
  56. >len);}
  57. >  temp[ADD_LEN-1] = '\0';
  58. >  return;
  59. >}
  60. >
  61.  
  62.  
  63. Hope this helps.
  64.  
  65. James
  66.  
  67. -- 
  68. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  69. *                                         *
  70. *            --        James McCallum        Ford Motor Company   *
  71. *                  / /         jmccall4@ford.com    +1 313 248 9017         *
  72. *                 | /                                 *
  73. *     *<%%%%%%%%%%|(===================================--             *
  74. *                 | \                                 *
  75. *           \ \      jmccall4@sl0270.srl.ford.com             *
  76. *                   --                                 *
  77. *                                         *
  78. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  79.  
  80.  
  81.